package com.example.hudongwx.food.activity;

import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.hudongwx.food.R;
import com.example.hudongwx.food.fragment.CommunityFragment;
import com.example.hudongwx.food.fragment.HomePageFragment;
import com.example.hudongwx.food.fragment.MyFragment;
import com.example.hudongwx.food.fragment.ShoppingCartFragment;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
    @ViewInject(android.R.id.tabhost)
    private FragmentTabHost fragmentTabHost;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        initFragment();

    }


    public void initFragment(){
        fragmentTabHost.setup(this,getSupportFragmentManager(),android.R.id.tabcontent);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("home").setIndicator(getTab("首页", R.drawable.select_home_icon)),HomePageFragment.class,null);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("community").setIndicator(getTab("社区",R.drawable.select_community_icon)),CommunityFragment.class,null);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("shopping").setIndicator(getTab("购物车",R.drawable.select_shopping_icon)),ShoppingCartFragment.class,null);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("my").setIndicator(getTab("我的",R.drawable.select_my_icon)),MyFragment.class,null);
        //设置中间没右竖线
        fragmentTabHost.getTabWidget().setDividerDrawable(null);
    }

    //设置tab的显示
    private View getTab(String tabName, int img){
        View view = getLayoutInflater().inflate(R.layout.tablehost_btn_item, null);
        ImageView iv = (ImageView) view.findViewById(R.id.table_host_image);
        TextView tv = (TextView) view.findViewById(R.id.table_host_text);
        tv.setTextSize(11);
        iv.setImageResource(img);
        tv.setText(tabName);
        return view;
    }
}
